//
//  CustomTabBar.m
//  Coco_Music
//
//  Created by 强哥 on 15/6/19.
//  Copyright (c) 2015年 寇广超. All rights reserved.
//

#import "CustomTabBar.h"


@implementation CustomTabBar


-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"myLogo.png"]];
        image.layer.borderColor = [UIColor blackColor].CGColor;
        _PlayerButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_PlayerButton setBackgroundImage:image.image forState:UIControlStateNormal];
        [_PlayerButton setBackgroundImage:image.image forState:UIControlStateHighlighted];
        [_PlayerButton addTarget:self action:@selector(GotoPlayer) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:_PlayerButton];
    }
    return self;
}

-(void)GotoPlayer
{
    
    [self.myPlay Present];
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    CGPoint point = _PlayerButton.center;
    point.x = self.bounds.size.width / 2;
    point.y = self.bounds.size.height / 2;
    _PlayerButton.center = point;
    self.backgroundColor = [UIColor whiteColor];
    CGRect rect = _PlayerButton.frame;
    rect.size = _PlayerButton.currentBackgroundImage.size;
    _PlayerButton.frame = CGRectMake(self.bounds.size.width/2-25, 0, 50, 50);
    CGFloat tabbarWidth = self.frame.size.width / 5;
    _PlayerButton.layer.masksToBounds = YES;
    _PlayerButton.layer.cornerRadius = 25;
    _PlayerButton.layer.borderWidth = 1;
    [self Animaction];
    
    NSInteger index = 0;
    for (UIView *child in self.subviews) {
        Class class = NSClassFromString(@"UITabBarButton");
        if ([child.class isSubclassOfClass:class]) {
            
            CGRect rect = child.frame;
            rect.origin.x = self.frame.size.width / 5 * index;
            rect.size.width = tabbarWidth;
            child.frame = rect;
            
            index++;
            if (index == 2) {
                index++;
            }
        }
        
    }

}


-(void)Animaction
{
    CABasicAnimation *basicAnimaction = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    [basicAnimaction setFromValue:[NSNumber numberWithInt:0]];
    [basicAnimaction setToValue:[NSNumber numberWithInt:M_PI*2]];
    [basicAnimaction setDuration:5];
    [basicAnimaction setRepeatCount:FLT_MAX];
    [basicAnimaction setAutoreverses:NO];
    [basicAnimaction setCumulative:YES];
    [_PlayerButton.layer addAnimation:basicAnimaction forKey:@"basicAnimation"];
}








/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
